import { Injectable } from '@nestjs/common';
import * as OSS from 'ali-oss';

@Injectable()
export class OssService {
  private client: OSS;

  constructor() {
    this.client = new OSS({
      region: 'oss-cn-beijing',
      accessKeyId: 'LTAI5tHbbWfUfj2kh4Vcn64J',
      accessKeySecret: 'mSIlcK4sUt4ufcCwQrNkzFjd78RuJo',
      bucket: 'xiaoandi-westlake',
    });
  }

    async uploadBuffer(buffer: Buffer, filename: string): Promise<string> {
    const objectKey = `images/${Date.now()}-${filename}`;
    const result = await this.client.put(objectKey, buffer);
    return result.url;
  }
}
